package com.qk.server.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.entity.Dept;
import com.qk.common.PageResult;
import com.qk.mapper.DeptMapper;
import com.qk.server.DeptServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServerImpl implements DeptServer {
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public void addDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insertDept(dept);
    }

    @Override
    public PageResult<Dept> findDeptByList(String name, Integer status, Integer page, Integer pageSize) {
        //第一步对参数进行初始化
        PageHelper.startPage(page,pageSize);
        //第二步进行查询
        List<Dept> listDept = deptMapper.selectDeptByList(name,status);
        //第三步进行封装
        Page<Dept> pageInfo = (Page) listDept;
        return new PageResult<Dept>(pageInfo.getTotal(),pageInfo.getResult());
    }

    @Override
    public Dept findDeptById(Integer id) {
        Dept dept = deptMapper.selectDeptById(id);
        return dept;
    }

    @Override
    public void updateById(Dept dept) {
        deptMapper.updateById(dept);
    }

    @Override
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }
}
